layui.use(['form', 'layer', 'table', 'laydate', 'func'], function () {
    var layer = layui.layer;
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;
    var func = layui.func;

    /**
     * 初始化表单，要加上，不然刷新部分组件可能会不加载
     */
    form.render();

    /**
     * 初始化表格
     */
    var SmPlanLog = {
        tableId: "SmPlanLogTable" //表格id
    };

    /**
     * 初始化表格的列
     */
    SmPlanLog.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'userName', align: "center", sort: true, title: '用户名'},
            {field: 'plName', align: "center", sort: true, title: '计划名称'},
            {field: 'gold', align: "center", sort: true, title: '奖励金币值',
                templet: function(object){
                    return "<span style='color:#FF5722'>" + object.gold + "</span>";
                }
            },
            {field: 'money', align: "center", sort: true, title: "金额",
                templet: function(object){
                    return "<span style='color:#009688'>" + object.money + "</span>元";
                }
            },
            {field: 'dayNum', align: "center", sort: true, title: '天数（第几天的打卡）',
                templet: function(object){
                    return "第" + object.dayNum + "天";
                }
            },
            {field: 'clockDate', align: "center", sort: true, title: '打卡时间'}
        ]];
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + SmPlanLog.tableId,
        url: Feng.ctxPath + '/web/smPlanLog/list',
        page: true,
        limits: [10, 15, 20, 25, 50, 100],
        limit: 15,
        height: "full-98",
        cellMinWidth: 100,
        cols: SmPlanLog.initColumn()
    });

    //日期范围
    laydate.render({
        elem: '#clockDate'
        ,range: true
    });

    /**
     * 点击查询按钮
     */
    SmPlanLog.search = function () {
        var queryData = {};
        queryData['userName'] = $("#userName").val();
        queryData['clockDate'] = $("#clockDate").val();
        table.reload(SmPlanLog.tableId, {
            where: queryData, page: {curr: 1}
        });
    };

    /**
     * 点击重置按钮
     */
    SmPlanLog.reset = function () {
        $("#userName").val("");
        $("#clockDate").val("");

        form.render();

        var queryData = {};
        queryData['userName'] = "";
        queryData['clockDate'] = "";
        SmPlanLog.search();
    };

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        SmPlanLog.search();
    });

    // 重置按钮点击事件
    $('#btnReset').click(function () {
        SmPlanLog.reset();
    });

    // 工具条点击事件
    // table.on('tool(' + UserGoldLog.tableId + ')', function (obj) {
    //     var data = obj.data;
    //     var layEvent = obj.event;
    //
    //     if (layEvent === 'edit') {
    //         UserGoldLog.onEdit(data);
    //     } else if (layEvent === 'delete') {
    //         UserGoldLog.onDelete(data);
    //     }
    // });

});

$(function () {
    var panehHidden = false;
    if ($(this).width() < 769) {
        panehHidden = true;
    }
    $('#myContiner').layout({initClosed: panehHidden, west__size: 260});
});